package org.snail.common.dingding.chat;

import com.dingtalk.open.client.ServiceFactory;
import com.dingtalk.open.client.api.model.corp.MessageBody;
import com.dingtalk.open.client.api.model.corp.MessageSendResult;
import com.dingtalk.open.client.api.service.corp.MessageService;
import com.dingtalk.open.client.common.SdkInitException;
import com.dingtalk.open.client.common.ServiceException;
import com.dingtalk.open.client.common.ServiceNotExistException;

/**
 * 发送个人消息
 */
public class UserMessageHelper {

    /**
     * 发送个人消息
     */
    public static String  sendMessageToUser(String access_token,  String sender, String cid, String msgtype, MessageBody message)
            throws ServiceNotExistException, SdkInitException, ServiceException {
        MessageService messageService = ServiceFactory.getInstance().getOpenService(MessageService.class);
       return messageService.sendToNormalConversation(access_token, sender, cid, msgtype, message);
    }

    /**
     * 发送个人消息
     */
    public static MessageSendResult sendMessageToUser(String access_token, String touser, String toparty, String agentid, String msgtype, MessageBody message)
            throws ServiceNotExistException, SdkInitException, ServiceException {
        MessageService messageService = ServiceFactory.getInstance().getOpenService(MessageService.class);
        return messageService.sendToCorpConversation(access_token, touser, toparty, agentid, msgtype, message);
    }

}
